<pre><?php
$table = 'test';

$c = mysql_connect('localhost','root','beresta');
mysql_select_db('xicms');
$res = mysql_query('Describe '.$table);  
?>&lt;form class="niceform"  action="/<?php echo $table;?>/&lt;?php echo $this->action; ?>/id/&lt;?php echo $this->item->id; ?>" method="post">
 &lt;input type="hidden" name="id" value="&lt;?php echo $this->item->id; ?>" />
        &lt;fieldset>
            &lt;?php if(!empty($this->message)) :?>
            &lt;dl id="message">
                &lt;dt>&lt;/dt>
                &lt;dd>&lt;b style="color:red;">&lt;?php echo $this->message;?>&lt;/b>&lt;/dd>
            &lt;/dl>
            &lt;?php endif; ?>
<?php   

While($row = mysql_fetch_assoc($res)) {
    //echo '<b><h3>'.$row['Field'].' '.$row['Type'].' ['.substr($row['Type'],0,3).']</h3></b><br>';
    switch(substr($row['Type'],0,3)){
        case 'int':
        case 'enu':
        case 'tin': ?>
&lt;dl>
                &lt;dt>&lt;label for="<?php echo $row['Field'];?>"><?php echo str_replace('_',' ',ucfirst($row['Field']));?>&lt;/label>&lt;/dt>
                &lt;dd>
                    &lt;select id="<?php echo $row['Field'];?>" name="<?php echo $row['Field'];?>" size="1">
                        &lt;?php foreach($this-><?php echo $row['Field'];?>s as $key=>$value) { ?> 
                        &lt;option value="&lt;?php echo $key;?>" &lt;?php echo $this->escape(trim($this->item-><?php echo $row['Field'];?>))==$key?' selected ':'';?>>&lt;?php echo $value;?>&lt;/option>
                        &lt;?php } ?>
                    &lt;/select>
                &lt;/dd>
            &lt;/dl>        
            <?php 
            break;
        case 'dat': ?>
&lt;dl>
                &lt;dt>&lt;label for="<?php echo $row['Field'];?>"><?php echo str_replace('_',' ',ucfirst($row['Field']));?>&lt;/label>&lt;/dt>
                &lt;dd>&lt;input type="text" size="10" id="<?php echo $row['Field'];?>" name="<?php echo $row['Field'];?>" value="&lt;?php echo $this->escape(trim($this->item-><?php echo $row['Field'];?>));?>">
                &lt;img id="<?php echo $row['Field'];?>_trigger" src="/public/images/cal.gif" style="padding:6px;" onclick="displayCalendar(document.getElementById('<?php echo $row['Field'];?>'),'yyyy-mm-dd',this);">&lt;/dd>
            &lt;/dl>
            <?php 
            break;
        case 'tim': ?>
&lt;dl>
                &lt;dt>&lt;label for="<?php echo $row['Field'];?>"><?php echo str_replace('_',' ',ucfirst($row['Field']));?>&lt;/label>&lt;/dt>
                &lt;dd>&lt;input type="text" size="5" id="<?php echo $row['Field'];?>" name="<?php echo $row['Field'];?>" value="&lt;?php echo $this->escape(trim($this->item-><?php echo $row['Field'];?>));?>">
            &lt;/dl>
            <?php 
            break;
        case 'tex': ?>
&lt;dl>
                &lt;dt>&lt;label for="<?php echo $row['Field'];?>"><?php echo str_replace('_',' ',ucfirst($row['Field']));?>&lt;/label>&lt;/dt>
                &lt;dd>&lt;textarea id="<?php echo $row['Field'];?>" name="<?php echo $row['Field'];?>"  rows="5" cols="36">&lt;?php echo $this->escape(trim($this->item-><?php echo $row['Field'];?>));?>&lt;/textarea>&lt;/dd> 
            &lt;/dl>
            <?php 
            break;
        default: ?>
&lt;dl>
                &lt;dt>&lt;label for="<?php echo $row['Field'];?>"><?php echo str_replace('_',' ',ucfirst($row['Field']));?>&lt;/label>&lt;/dt>
                &lt;dd>&lt;input type="text" size="54" id="<?php echo $row['Field'];?>" name="<?php echo $row['Field'];?>" value="&lt;?php echo $this->escape(trim($this->item-><?php echo $row['Field'];?>));?>">&lt;/dd>
            &lt;/dl>        
            <?php 
            break;
    }
    
}
?>
        &lt;dl class="submit">
            &lt;a href="javascript:document.forms[0].submit();" class="bt_blue">&lt;span class="bt_blue_lft">&lt;/span>&lt;strong>Save&lt;/strong>&lt;span class="bt_blue_r">&lt;/span>&lt;/a>
            &lt;a href="/<?php echo $table;?>/&lt;?php echo $this->action; ?>/id/&lt;?php echo $this->item->id; ?>" class="bt_blue">&lt;span class="bt_blue_lft">&lt;/span>&lt;strong>Cancel&lt;/strong>&lt;span class="bt_blue_r">&lt;/span>&lt;/a>
         &lt;/dl>
    &lt;/fieldset>
        
 &lt;/form>